package com.baske.sort;

import java.util.HashSet;
import java.util.Set;

public class LinkedListFindCycle {

    public static void main(String[] args) {
        ListNode listNode2 = new ListNode(2);
        ListNode listNode1 = new ListNode(1,listNode2);
    }

    public static class ListNode {
        int val;
        ListNode next;
        public ListNode() {}
        public ListNode(int val) {
            this.val = val;
        }
        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    /**
     * 链表找环
     */
    public ListNode LinkedListFindRing(ListNode head) {
        Set<ListNode> set  = new HashSet<>();
        while (head != null) {
            int size = set.size();
            set.add(head);
            if (size == set.size()) {
                return head;
            }
            head = head.next;
        }
        return null;
    }


}
